# www.goubanjia.com使用该网站提供的代理ip，隐藏本机ip

import requests
from lxml import etree

if __name__ == '__main__':
    # 请求百度ip地址页
    url = 'https://www.baidu.com/s?wd=ip'
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.3'}
    # page_text = requests.get(url=url, headers=headers).text
    # tree = etree.HTML(page_text)
    # ip = tree.xpath('/html/body/p[1]/a/text()')[0]
    # print('未使用代理本次请求ip是：', ip)
    page_text_agent = requests.get(url=url, headers=headers, proxies={'https': 'https://60.5.40.94:9999'}).text
    # tree = etree.HTML(page_text_agent)
    # ip_agent = tree.xpath('/html/body/p[1]/a/text()')[0]
    # print('使用代理后本次请求ip是：', ip_agent)
    with open('ip.html', 'w', encoding='utf-8') as fp:
        fp.write(page_text_agent)
